<?php

class GoodController extends FrontBaseC {

    /**
     * Declares class-based actions.
     */
    //瀑布流默认加载个数
    public $sault_num = 20;
    public $max_num = 100;

    public function actions() {
        
    }

    //商品内页
    public function actionShow() {
        $good_id = (int) $_GET['gid'];
        $GoodsModel = new GoodsModel();
        $good = $GoodsModel->getGoodBYGoodId($good_id);
        //判断是否蜘蛛
        if (!UrlClass::getrobot()) {
            if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] && $good->item_type < 10) {
                $domain = GuestRefererModel::model()->getDomain($_SERVER['HTTP_REFERER']);
                //以下来源域名不跳
                if (!in_array($domain['root_domain'], array('baidu.com', 'so.com', 'soso.com', 'sogou.com', 'google.com', 'bing.com', 'yahoo.com', '360.cn', '2345.com', 'hao123.com', 'duba.com', 'uc123.com', 'qq.com'))) {
                    $this->redirect(array('/front/good/skip', 'gid' => $good_id));
                }
            }
        }

        $page = isset($_GET['page']) ? $_GET['page'] : 1; //第几页
        //$cat_goods = $GoodsModel->getHomeGoods($this->sault_num);
        $cat_goods = $GoodsModel->getGoodsForZhiZu($good_id,$this->sault_num);
        $this->description = $good->goods_name . "介绍：" . $good->goods_brief."。温馨提醒：".$good->goods_name."已经过质检员精心筛选,可以放心购买。";
        $this->keywords = "$good->goods_name,$good->goods_name" ."价格";
        $this->title = "【".$good->goods_name."】".$good->goods_name."价格及报价 - 1折网";
        //shuffle($cat_goods[0]);

        if ($good) {
            $this->layout = 'theme.views.layouts.FrontNoFixedContent';
            $this->render('goodDetail', array(
                'good' => $good,
                'good2' => $good,
                'cat_goods' => $cat_goods[0],
                'page' => $page,
            ));
            return;
        }
        $this->render('noGoodShow');
    }

    /*
    public function actionAjaxShow(){
        $this->layout = false;
        $GoodsModel = new GoodsModel();  
        $cat_goods = $GoodsModel->getHomeGoods($this->sault_num);
        shuffle($cat_goods[0]);
        $this->render('goodDetail_list', array(
            'cat_goods' => $cat_goods[0],
        ));                     
    }
    */
    /*
     * ajax请求 homegoods 
     * @author SongXing
     */

    public function actionAjax() {

        $GoodsModel = new GoodsModel();
        $page = isset($_GET['page']) ? $_GET['page'] : 1; //第几页



        if (intval($this->max_num / $this->sault_num + 1) >= $page) {
            $home_goods = $GoodsModel->getHomeGoods($this->sault_num);
            $goods = $home_goods[0];
            shuffle($goods);
        } else
            return "";

        header('Content-Type: text/html; charset=utf-8');

        foreach ($goods as $good) {
            include $this->getViewFile('../lib/goodlist_detail');
        }
    }

    public function actionSkip() {
        $good_id = (int) $_GET['gid'];
        $GoodsModel = new GoodsModel();
        $good = $GoodsModel->getGoodBYGoodId($good_id);
        if ($good) {
            $this->layout = 'theme.views.layouts.FrontNoHeaderContent';
            $this->render('show', array(
                'product_id' => $good->product_id,
            ));
            return;
        }
        $this->render('noGoodShow');
    }



    public function actionRedeemSkip() {
        $good_id = (int) $_GET['gid'];
        $RedeemModel = new RedeemModel();
        $good = $RedeemModel->getGoodBYGoodId($good_id);
        if ($good) {
            $this->layout = 'theme.views.layouts.FrontNoHeaderContent';
            $this->render('show', array(
                'product_id' => $good->product_id,
            ));
            return;
        }
        $this->render('noGoodShow');
    }    

}
